package main

import (
	"fmt"
	"net/http"
	"xwWechatPublic/models"
	"xwWechatPublic/routers"
	"xwWechatPublic/utils/encryption"
	"xwWechatPublic/utils/gcache"
	"xwWechatPublic/utils/logging"
	"xwWechatPublic/utils/setting"
)

func init() {
	setting.Setup()
	gcache.Setup()
	logging.Setup()
	models.Setup()
	//util.Setup()
	encryption.Setup()
}

//主函数
func main() {

	routersInit := routers.InitRouter()
	readTimeout := setting.ServerSetting.ReadTimeout
	writeTimeout := setting.ServerSetting.WriteTimeout
	endPoint := fmt.Sprintf("%s:%d",
		setting.ServerSetting.HttpAddr, setting.ServerSetting.HttpPort)
	maxHeaderBytes := 1 << 20

	server := &http.Server{
		Addr:           endPoint,
		Handler:        routersInit,
		ReadTimeout:    readTimeout,
		WriteTimeout:   writeTimeout,
		MaxHeaderBytes: maxHeaderBytes,
	}
	fmt.Printf("[info] start http server listening %s\n", endPoint)
	logging.Info("服务正常启动 listening[%v]\n", endPoint)

	err := server.ListenAndServe()
	if err != nil {
		fmt.Printf("启动服务ERROR[%v]", err.Error())
	}
	logging.Info("服务正常启动[%v]", endPoint)

	//s := &http.Server{
	//	Addr:           "127.0.0.1:10070",
	//	//Handler:        routersInit,
	//	ReadTimeout:    10 * time.Second,
	//	WriteTimeout:   10 * time.Second,
	//	MaxHeaderBytes: 1 << 20,
	//}
	//s.ListenAndServe()
}
